<?php


namespace app\community\oauth2\Repository;


use app\community\oauth2\Entities\ScopeEntity;
use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;

class ScopeRepository implements ScopeRepositoryInterface
{

    public function getScopeEntityByIdentifier($identifier)
    {
        // TODO: Implement getScopeEntityByIdentifier() method.
        return new ScopeEntity($identifier);
    }

    public function finalizeScopes(array $scopes, $grantType, ClientEntityInterface $clientEntity, $userIdentifier = null): array
    {
        // TODO: Implement finalizeScopes() method.
        if (!is_array($userIdentifier)) {
            $userIdentifier = [$userIdentifier];
        }
        return array_map(function ($userId) {
            return new ScopeEntity($userId);
        }, $userIdentifier ?: []);
    }
}